<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

$strcodi = $_REQUEST["txtCodigo"];
$strnomb = $_REQUEST["ATxtNombre"];
$strusua = $_REQUEST["ATxtUsuario"];
$strclav = $_REQUEST["ATxtClave"];
$strclv2 = $_REQUEST["ATxtClave"];
$strperf = $_REQUEST["CmbPerfil"];
$strnodo = $_REQUEST["CboNodo"];
$Opcion = $_REQUEST["Opcion"];
   //'response.write(strnomb)
   //'response.write "<br>Opcion = " & Opcion
   //'re
switch($Opcion){
    case 1:
        $tipo = "UPDATE";
        $tabla = "solotb_usuario";
        $SoloSQL = "$tipo $tabla set ";
        $SoloSQL .=  "co_usua='$strusua',";
        $SoloSQL .=  "no_usua='$strnomb',";
        $SoloSQL .=  "cl_usua='$strclav',";
        $SoloSQL .=  "co_perf=$strperf";
        $SoloSQL .=  " where nu_usua=$strcodi";
        $SoloSQL .=  " and nodo=$strnodo";
        //'response.write "<br>SoloSQL="& SoloSQL
        //'re
        $pagina = "solotrn_ModificarUsuario.php";
        $opc = "&Opcion=1&OpbTipo=T&txtCodigo=$strcodi";
        $co_tran = 201;
        $ds_tran = "Actualizar Usuario $strusua";
        break;
    case 2:
        $tipo = "DELETE";
        $tabla = "solotb_usuario";
        $SoloSQL = "$tipo from $tabla ";
        $SoloSQL .=  " where nu_usua=$strcodi and nodo=$strnodo";
    //'response.write "<br>SoloSQL="& SoloSQL
        //'re
        $pagina = "solotrn_EliminarUsuario.php";
        $opc = "&Opcion=2&OpbTipo=T&txtCodigo=$strcodi";
        $co_tran = 201;
        $ds_tran = "Eliminar Usuario $strusua";
        break;
    case 3:
        $SoloSQL="select (max(nu_usua)+1) as maximo from solotb_usuario where nodo= $strnodo";
        $Maximo = SoloFun_Maximo("nu_usua","solotb_usuario");
                   //'rw "SoloSQL",Maximo
                   //'re
        $fecha_ing = date("Y-m-d");
        //$fecha_ing = formatFecha($fecha_ing,"DD/MM/YYYY","YYYY-MM-DD");
        $tipo = "INSERT";
        $tabla = "solotb_usuario";
        $SoloSQL = "$tipo into $tabla values(";
        $SoloSQL .=  "$Maximo,";
        $SoloSQL .=  "'$strusua',";
        $SoloSQL .=  "'$strnomb',";
        $SoloSQL .=  "'$strclav',";
        $SoloSQL .=  "$strperf,";
        //'				   $SoloSQL .=  "'"  & now & "',"
        $SoloSQL .=  "'$fecha_ing',";
        $SoloSQL .=  "null,";
        $SoloSQL .=  "$strnodo)";

    //				   'rw "",SoloSQL
    //				   're
    //'''				   $SoloSQL .=  "'"  & Day(Date)&"/"&Month(Date)&"/"&Year(Date) & "')"
    //'				   response.write "<br>SoloSQL="&SoloSQL
        $pagina = "solotrn_ModificarUsuario.php";
        $opc = "&Opcion=3";//'&OpbTipo=T&max=" & maximo
        $co_tran = 201;
        $ds_tran = "Ingresar Usuario $strusua";
        break;
}
   
$err = 0;
//echo $SoloSQL;
$arrQueries = array();
array_push($arrQueries, $SoloSQL);
array_push($arrQueries, crearQueryLog($tabla, $tipo, $SoloSQL));

$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
//if(!$oConexion->EjecutarQuery($SoloSQL))
if(!$oConexion->EjecutarTransaccion($arrQueries))
    $strMsg = $pagina . "?SoloError=1&CboNodo=$strnodo$opc";
else{
    //SoloFun_IngresaLog(2,$co_tran,$ds_tran);
    $strMsg = $pagina . "?SoloError=0&CboNodo=$strnodo$opc";
    //$oConexion->liberarResultado();
}
$oConexion->Cerrar();
//echo $strMsg;
header ("Location: $strMsg");
?>